﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Special_Item
{
    public partial class Pro_Admin_Password : Form
    {
        public Pro_Admin_Password()
        {
            InitializeComponent();
        }

        private void Confirm_revision_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrWhiteSpace(this.old_pwd.Text))
            {
                MessageBox.Show("原密码不能为空！","提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
                this.old_pwd.Focus();
            }
            else if (string.IsNullOrWhiteSpace(this.new_pwd.Text))
            {
                MessageBox.Show("新密码不能为空！","提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
                this.new_pwd.Focus();
            }else if(this.old_pwd.Text.Equals(this.new_pwd.Text))
            {
                MessageBox.Show("新密码不能和原密码一样！", "提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
                this.new_pwd.Focus();
            }else if(string.IsNullOrWhiteSpace(this.Confirm_pwd.Text))
            {
                MessageBox.Show("确定密码不能为空！","提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
                this.Confirm_pwd.Focus();
            }
            else if (!this.new_pwd.Text.Equals(this.Confirm_pwd.Text))
            {
                MessageBox.Show("两次密码不一致！","提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
                this.Confirm_pwd.Focus();
            }
            else
            {
//                var stu = @"Data Source=.;
//                      Initial Catalog=Training_Project;
//                      Uid=hll;
//                      Pwd=123;";
//                var conn = new SqlConnection(stu);
//                try
//                {
//                    conn.Open();
//                    var sql = string.Format("select Passward from Manager_Login where Passward='{0}'", this.old_pwd.Text);
//                    SqlCommand comm = new SqlCommand(sql, conn);
//                    object obj = comm.ExecuteScalar();
//                    if (!this.old_pwd.Text.Equals(obj))
//                    {
//                        MessageBox.Show("你输入的原密码错误！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
//                        this.old_pwd.Focus();
//                    }
//                    else
//                    {
//                        var sql1 = string.Format("update Manager_Login set Passward='{0}' where Passward='{1}'", this.Confirm_pwd.Text, this.old_pwd.Text);
//                        SqlCommand comm1 = new SqlCommand(sql1, conn);
//                        int num = comm1.ExecuteNonQuery();
//                        if (num > 0)
//                        {
//                            Pro_Admin_Password1 pwd = new Pro_Admin_Password1();
//                            pwd.Show();
//                            this.Hide();
//                        }
//                        else
//                        {
//                            MessageBox.Show("修改失败！");
//                            this.old_pwd.Focus();
//                        }
//                    }
//                }
//                catch (Exception)
//                {

//                }
//                finally
//                {
//                    conn.Close();
//                }
            }
        }
    }
}
